package day7;

import java.util.Scanner;

// https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?tpId=122&tqId=33668&ru=/exam/oj
public class code2 {
    public static void main(String[] args) {
        // 0, 1, 1, 2, 3, 5, 8, 13, 21
        Scanner scanner = new Scanner(System.in);
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        int n = scanner.nextInt();
        while (n > f2) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        int step = Math.min(f2 - n,n - f1);
        System.out.println(step);
    }
}
